package com.toe.forum.webapi.controller;


import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.forum.service.UserEnshrineArticleService;
import com.toe.pojo.dto.forum.EnshrineArticleAddDTO;
import com.toe.pojo.dto.forum.EnshrineArticleUpdateDTO;
import com.toe.pojo.vo.forum.EnshrineArticleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户收藏文章表 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/uesr-enshrine-article")
@Api(tags = "收藏记录模块")
public class UserEnshrineArticleController {

    @Autowired
    private UserEnshrineArticleService userEnshrineArticleService;

    @ApiOperation("添加收藏记录")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody EnshrineArticleAddDTO enshrineArticleAddDTO){
        userEnshrineArticleService.insert(enshrineArticleAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除收藏记录")
    @PostMapping("/delete")
    public JsonResult<Void> delete(long userId,long articleId){
        userEnshrineArticleService.delete(userId,articleId);
        return JsonResult.ok();
    }

    @ApiOperation("删除指定收藏记录")
    @PostMapping("/delete/{id}")
    public JsonResult<Void> delete(@PathVariable long id){
        userEnshrineArticleService.deleteById(id);
        return JsonResult.ok();
    }

//    @ApiOperation("修改收藏记录")
//    @PostMapping("/update")
//    public JsonResult<Void> update(EnshrineArticleUpdateDTO enshrineArticleUpdateDTO){
//        userEnshrineArticleService.updateUserEnshrineArticle(enshrineArticleUpdateDTO);
//        return JsonResult.ok();
//    }

//    @ApiOperation("查询全部收藏记录")
//    @GetMapping("/select/list")
//    public JsonResult<List<EnshrineArticleVO>> selectAllEnshrine(){
//        List<EnshrineArticleVO> enshrineArticleVOS = userEnshrineArticleService.selectAllEnshrine();
//        return JsonResult.ok(enshrineArticleVOS);
//    }

//    @ApiOperation("分页查询全部收藏记录")
//    @GetMapping("/select/list/page")
//    public JsonResult<JsonPage<EnshrineArticleVO>> selectAllEnshrinePage(Integer pageNum,Integer pageSize){
//        JsonPage<EnshrineArticleVO> enshrineArticleVOJsonPage = userEnshrineArticleService.selectAllEnshrinePage(pageNum, pageSize);
//        return JsonResult.ok(enshrineArticleVOJsonPage);
//    }
//
//    @ApiOperation("查询某篇文章的全部收藏记录")
//    @GetMapping("/select/article/{articleId}")
//    public JsonResult<List<EnshrineArticleVO>> selectAllEnshrineByArticleId(@PathVariable long articleId){
//        List<EnshrineArticleVO> enshrineArticleVOS = userEnshrineArticleService.selectAllEnshrineByArticleId(articleId);
//        return JsonResult.ok(enshrineArticleVOS);
//    }
//
//    @ApiOperation("分页查询某篇文章的全部收藏记录")
//    @GetMapping("/select/article/{articleId}/page")
//    public JsonResult<JsonPage<EnshrineArticleVO>> selectAllEnshrineByArticleIdPage(@PathVariable long articleId,Integer pageNum,Integer pageSize){
//        JsonPage<EnshrineArticleVO> enshrineArticleVOJsonPage = userEnshrineArticleService.selectAllEnshrineByArticleIdPage(articleId, pageNum, pageSize);
//        return JsonResult.ok(enshrineArticleVOJsonPage);
//    }

    @ApiOperation("查询指定收藏记录是否存在")
    @GetMapping("/select")
    public  JsonResult<Boolean> selectEnshrineById(long userId,long articleId){
        EnshrineArticleVO enshrineArticleVO = userEnshrineArticleService.selectEnshrineById(userId, articleId);
        Boolean isAlready = false;
        if (enshrineArticleVO!=null){
            isAlready = true;
        }
        return JsonResult.ok(isAlready);
    }
}

